package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.dao.impl.UserDaoImpl;
import com.itheima.domain.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.SpringVersion;

public class AppForIoc {
    public static void main(String[] args) {
        User user = new User();
        user.setId(100L);
        user.setUserName("Spring小能手");
        user.setAge(21);
        //TODO 将userDao该为由spring创建对象,获取对象
        UserDao userDao = new UserDaoImpl();
        userDao.save(user);
        //交由spring管理后
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao1 = (UserDao) applicationContext.getBean("userDao");
        userDao1.save(user);
    }
}